var hiddenCalendar = new Array();
var hiddenCalendars = 1;
for(var i = 1;i<20;i++){hiddenCalendar[i] = 1;}
$(document).ready(begin);
function begin(){
$("#hidecalendars").click(hidecalendars);
$(".calendarcol").click(function(){$(this).toggleClass("gris");});
$(".calendarcol").click(togglecalendars);
	$("#anonimo").click(function(){$(".event").css("background","black");$(".motivoevento").text("");$(".event").css("color","white");});
	$("#anonimo2").click(function(){$(".motivoevento").text("");});
	$("#newEvent").hide();
	$(".day").click(show);
	//$("#buttonAddCalendar").click(showCalendar);
        $("#buttonSetDesiredWeather").click(showSetDesiredWeather);
        //$("#closeNewCalendar").click(closeCalendar);
        $("#closeSetDesiredWeather").click(closeSetDesiredWeather);
	//$(".delete").hide();
	//$(".day").hover(showdelete)
	$(".event").draggable();
	$( ".day" ).droppable({
	      drop: function( event, ui ) {
	        $("#ajax").load("actions/change.jsp?event_id="+ui.draggable.attr("event_id")+"&newDay="+$(this).attr("day"));
                console.log("The event that I'm moving is: "+ui.draggable.attr("event_id"));
                console.log("The day to which it is moving is: "+$(this).attr("day"));
	      	setTimeout(function(){window.location="?";},1000);
	      }
	    });
	    $("#closeNewEvent").click(close);
}
function hidecalendars(){
	if(hiddenCalendars == 1){
		$("#calendars").fadeOut("slow");
		hiddenCalendars = 0;
	
	}else{
		$("#calendars").fadeIn("slow");
		hiddenCalendars = 1;
	}
}
function togglecalendars(){
	var coge = $(this).attr("");
	if(hiddenCalendar[$(this).attr('idcalendar')] == 1){
		$('[idcalday = '+$(this).attr('idcalendar')+']').fadeOut("slow");
		hiddenCalendar[$(this).attr('idcalendar')] = 0;
	}else{
		$('[idcalday = '+$(this).attr('idcalendar')+']').fadeIn("slow");
		hiddenCalendar[$(this).attr('idcalendar')] = 1;
	}
}
function show(){
	$("#calendar").addClass("blur");
	$("#newEvent").fadeIn();
	var day = $(this).attr("id");
	var numday = $(this).attr("day");
	$("#tellMeDay").val(numday);
	$("#newEvent").append('<input type="hidden" name="day" value="'+day+'">');
}
function showCalendar(){
	$("#calendar").addClass("blur");
	$("#newCalendarForm").fadeIn();
	/*var day = $(this).attr("id");
	var numday = $(this).attr("day");
	$("#tellMeDay").val(numday);
	$("#newEvent").append('<input type="hidden" name="day" value="'+day+'">');*/
}
function showSetDesiredWeather(){
	$("#newEvent").addClass("blur");
	$("#setDesiredWeather").fadeIn();
	/*var day = $(this).attr("id");
	var numday = $(this).attr("day");
	$("#tellMeDay").val(numday);
	$("#newEvent").append('<input type="hidden" name="day" value="'+day+'">');*/
}
function close(){
	$("#calendar").removeClass("blur");
	$("#newEvent").fadeOut();
}
function closeSetDesiredWeather(){
	$("#newEvent").removeClass("blur");
	$("#setDesiredWeather").fadeOut();
}
function showdelete(){
	
}
